home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / unixccompiler.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  9KB  |  298 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''distutils.unixccompiler
  5.  
  6. Contains the UnixCCompiler class, a subclass of CCompiler that handles
  7. the "typical" Unix-style command-line C compiler:
  8.   * macros defined with -Dname[=value]
  9.   * macros undefined with -Uname
  10.   * include search directories specified with -Idir
  11.   * libraries specified with -lllib
  12.   * library search directories specified with -Ldir
  13.   * compile handled by \'cc\' (or similar) executable with -c option:
  14.     compiles .c to .o
  15.   * link static library handled by \'ar\' command (possibly with \'ranlib\')
  16.   * link shared library handled by \'cc -shared\'
  17. '''
  18. __revision__ = '$Id: unixccompiler.py 74729 2009-09-09 08:34:06Z tarek.ziade $'
  19. import os
  20. import sys
  21. from types import StringType, NoneType
  22. from distutils import sysconfig
  23. from distutils.dep_util import newer
  24. from distutils.ccompiler import CCompiler, gen_preprocess_options, gen_lib_options
  25. from distutils.errors import DistutilsExecError, CompileError, LibError, LinkError
  26. from distutils import log
  27.  
  28. def _darwin_compiler_fixup(compiler_so, cc_args):
  29.     """
  30.     This function will strip '-isysroot PATH' and '-arch ARCH' from the
  31.     compile flags if the user has specified one them in extra_compile_flags.
  32.  
  33.     This is needed because '-arch ARCH' adds another architecture to the
  34.     build, without a way to remove an architecture. Furthermore GCC will
  35.     barf if multiple '-isysroot' arguments are present.
  36.     """
  37.     stripArch = stripSysroot = 0
  38.     compiler_so = list(compiler_so)
  39.     kernel_version = os.uname()[2]
  40.     major_version = int(kernel_version.split('.')[0])
  41.     if major_version < 8:
  42.         stripArch = stripSysroot = True
  43.     else:
  44.         stripArch = '-arch' in cc_args
  45.         stripSysroot = '-isysroot' in cc_args
  46.     if stripArch or 'ARCHFLAGS' in os.environ:
  47.         while None:
  48.             
  49.             try:
  50.                 index = compiler_so.index('-arch')
  51.                 del compiler_so[index:index + 2]
  52.             continue
  53.             except ValueError:
  54.                 break
  55.                 continue
  56.             
  57.  
  58.     None<EXCEPTION MATCH>ValueError
  59.     if 'ARCHFLAGS' in os.environ and not stripArch:
  60.         compiler_so = compiler_so + os.environ['ARCHFLAGS'].split()
  61.     
  62.     if stripSysroot:
  63.         
  64.         try:
  65.             index = compiler_so.index('-isysroot')
  66.             del compiler_so[index:index + 2]
  67.         except ValueError:
  68.             pass
  69.         except:
  70.             None<EXCEPTION MATCH>ValueError
  71.         
  72.  
  73.     None<EXCEPTION MATCH>ValueError
  74.     sysroot = None
  75.     if '-isysroot' in cc_args:
  76.         idx = cc_args.index('-isysroot')
  77.         sysroot = cc_args[idx + 1]
  78.     elif '-isysroot' in compiler_so:
  79.         idx = compiler_so.index('-isysroot')
  80.         sysroot = compiler_so[idx + 1]
  81.     
  82.     if sysroot and not os.path.isdir(sysroot):
  83.         log.warn("Compiling with an SDK that doesn't seem to exist: %s", sysroot)
  84.         log.warn('Please check your Xcode installation')
  85.     
  86.     return compiler_so
  87.  
  88.  
  89. class UnixCCompiler(CCompiler):
  90.     compiler_type = 'unix'
  91.     executables = {
  92.         'preprocessor': None,
  93.         'compiler': [
  94.             'cc'],
  95.         'compiler_so': [
  96.             'cc'],
  97.         'compiler_cxx': [
  98.             'cc'],
  99.         'linker_so': [
  100.             'cc',
  101.             '-shared'],
  102.         'linker_exe': [
  103.             'cc'],
  104.         'archiver': [
  105.             'ar',
  106.             '-cr'],
  107.         'ranlib': None }
  108.     if sys.platform[:6] == 'darwin':
  109.         executables['ranlib'] = [
  110.             'ranlib']
  111.     
  112.     src_extensions = [
  113.         '.c',
  114.         '.C',
  115.         '.cc',
  116.         '.cxx',
  117.         '.cpp',
  118.         '.m']
  119.     obj_extension = '.o'
  120.     static_lib_extension = '.a'
  121.     shared_lib_extension = '.so'
  122.     dylib_lib_extension = '.dylib'
  123.     static_lib_format = shared_lib_format = dylib_lib_format = 'lib%s%s'
  124.     if sys.platform == 'cygwin':
  125.         exe_extension = '.exe'
  126.     
  127.     
  128.     def preprocess(self, source, output_file = None, macros = None, include_dirs = None, extra_preargs = None, extra_postargs = None):
  129.         (ignore, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
  130.         pp_opts = gen_preprocess_options(macros, include_dirs)
  131.         pp_args = self.preprocessor + pp_opts
  132.         if output_file:
  133.             pp_args.extend([
  134.                 '-o',
  135.                 output_file])
  136.         
  137.         if extra_preargs:
  138.             pp_args[:0] = extra_preargs
  139.         
  140.         if extra_postargs:
  141.             pp_args.extend(extra_postargs)
  142.         
  143.         pp_args.append(source)
  144.         if self.force and output_file is None or newer(source, output_file):
  145.             if output_file:
  146.                 self.mkpath(os.path.dirname(output_file))
  147.             
  148.             
  149.             try:
  150.                 self.spawn(pp_args)
  151.             except DistutilsExecError:
  152.                 msg = None
  153.                 raise CompileError, msg
  154.             except:
  155.                 None<EXCEPTION MATCH>DistutilsExecError
  156.             
  157.  
  158.         None<EXCEPTION MATCH>DistutilsExecError
  159.  
  160.     
  161.     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
  162.         compiler_so = self.compiler_so
  163.         if sys.platform == 'darwin':
  164.             compiler_so = _darwin_compiler_fixup(compiler_so, cc_args + extra_postargs)
  165.         
  166.         
  167.         try:
  168.             self.spawn(compiler_so + cc_args + [
  169.                 src,
  170.                 '-o',
  171.                 obj] + extra_postargs)
  172.         except DistutilsExecError:
  173.             msg = None
  174.             raise CompileError, msg
  175.  
  176.  
  177.     
  178.     def create_static_lib(self, objects, output_libname, output_dir = None, debug = 0, target_lang = None):
  179.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  180.         output_filename = self.library_filename(output_libname, output_dir = output_dir)
  181.         if self._need_link(objects, output_filename):
  182.             self.mkpath(os.path.dirname(output_filename))
  183.             self.spawn(self.archiver + [
  184.                 output_filename] + objects + self.objects)
  185.             if self.ranlib:
  186.                 
  187.                 try:
  188.                     self.spawn(self.ranlib + [
  189.                         output_filename])
  190.                 except DistutilsExecError:
  191.                     msg = None
  192.                     raise LibError, msg
  193.                 except:
  194.                     None<EXCEPTION MATCH>DistutilsExecError
  195.                 
  196.  
  197.             None<EXCEPTION MATCH>DistutilsExecError
  198.         else:
  199.             log.debug('skipping %s (up-to-date)', output_filename)
  200.  
  201.     
  202.     def link(self, target_desc, objects, output_filename, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
  203.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  204.         (libraries, library_dirs, runtime_library_dirs) = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
  205.         library_dirs = _[1]
  206.         runtime_library_dirs = _[2]
  207.         lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, libraries)
  208.         if type(output_dir) not in (StringType, NoneType):
  209.             raise TypeError, "'output_dir' must be a string or None"
  210.         type(output_dir) not in (StringType, NoneType)
  211.         if self._need_link(objects, output_filename):
  212.             ld_args = objects + self.objects + lib_opts + [
  213.                 '-o',
  214.                 output_filename]
  215.             if extra_preargs:
  216.                 ld_args[:0] = extra_preargs
  217.             
  218.             if extra_postargs:
  219.                 ld_args.extend(extra_postargs)
  220.             
  221.             self.mkpath(os.path.dirname(output_filename))
  222.             
  223.             try:
  224.                 if target_desc == CCompiler.EXECUTABLE:
  225.                     linker = self.linker_exe[:]
  226.                 else:
  227.                     linker = self.linker_so[:]
  228.                 if target_lang == 'c++' and self.compiler_cxx:
  229.                     i = 0
  230.                     if os.path.basename(linker[0]) == 'env':
  231.                         i = 1
  232.                         while '=' in linker[i]:
  233.                             i = i + 1
  234.                     
  235.                     linker[i] = self.compiler_cxx[i]
  236.                 
  237.                 if sys.platform == 'darwin':
  238.                     linker = _darwin_compiler_fixup(linker, ld_args)
  239.                 
  240.                 self.spawn(linker + ld_args)
  241.             except DistutilsExecError:
  242.                 msg = None
  243.                 raise LinkError, msg
  244.             except:
  245.                 None<EXCEPTION MATCH>DistutilsExecError
  246.             
  247.  
  248.         None<EXCEPTION MATCH>DistutilsExecError
  249.         log.debug('skipping %s (up-to-date)', output_filename)
  250.  
  251.     
  252.     def library_dir_option(self, dir):
  253.         return '-L' + dir
  254.  
  255.     
  256.     def runtime_library_dir_option(self, dir):
  257.         compiler = os.path.basename(sysconfig.get_config_var('CC'))
  258.         if sys.platform[:6] == 'darwin':
  259.             return '-L' + dir
  260.         if sys.platform[:5] == 'hp-ux':
  261.             if 'gcc' in compiler or 'g++' in compiler:
  262.                 return [
  263.                     '-Wl,+s',
  264.                     '-L' + dir]
  265.             return [
  266.                 '+s',
  267.                 '-L' + dir]
  268.         if sys.platform[:7] == 'irix646' or sys.platform[:6] == 'osf1V5':
  269.             return [
  270.                 '-rpath',
  271.                 dir]
  272.         if compiler[:3] == 'gcc' or compiler[:3] == 'g++':
  273.             return '-Wl,-R' + dir
  274.         return '-R' + dir
  275.  
  276.     
  277.     def library_option(self, lib):
  278.         return '-l' + lib
  279.  
  280.     
  281.     def find_library_file(self, dirs, lib, debug = 0):
  282.         shared_f = self.library_filename(lib, lib_type = 'shared')
  283.         dylib_f = self.library_filename(lib, lib_type = 'dylib')
  284.         static_f = self.library_filename(lib, lib_type = 'static')
  285.         for dir in dirs:
  286.             shared = os.path.join(dir, shared_f)
  287.             dylib = os.path.join(dir, dylib_f)
  288.             static = os.path.join(dir, static_f)
  289.             if os.path.exists(dylib):
  290.                 return dylib
  291.             if os.path.exists(shared):
  292.                 return shared
  293.             if os.path.exists(static):
  294.                 return static
  295.         
  296.  
  297.  
  298.